//
//  AddController.m
//  敢唆嘛!
//
//  Created by lanou on 15/11/25.
//  Copyright © 2015年 zms. All rights reserved.
//

#import "AddController.h"
#import "Device.h"
#import "AddDetailController.h"

typedef NS_ENUM(NSInteger, channelState){
    channelUnknow,//未选中
    channelReality,// 选中真事
    channelCreation,// 选中创作
    channelTravel,//选中游记
    channelSecret//选中秘密
};


@interface AddController ()
@property(nonatomic , assign)channelState state;//频道状态
@property(nonatomic , strong)UIImageView *coverImageView;//封面图片
@property(nonatomic , strong)UILabel *titleLabel;//标题
@property(nonatomic , strong)UIImageView *cirleImageView;//小圆圈
@property(nonatomic , strong)UILabel *tagLabel;//标签

@property(nonatomic , strong)UILabel *userNameLabel;//用户名称
@end

@implementation AddController

-(void)viewDidAppear:(BOOL)animated
{
    if(self.state == channelUnknow)
    {
        self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquanGray"];
        self.tagLabel.text = @"未选择频道";
    }
    else if(self.state == channelReality)
    {
        self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan"];
        self.tagLabel.text = @"真事";
    }
    else if(self.state == channelCreation)
    {
        self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-3"];
        self.tagLabel.text = @"创作";
    }
    else if(self.state == channelTravel)
    {
        self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-2"];
        self.tagLabel.text = @"游记";
    }
    else if(self.state == channelSecret)
    {
        self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-1"];
        self.tagLabel.text = @"秘密";
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //    设置返回按钮
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, KSWidth/18, KSWidth/18);
    [backBtn setImage:[UIImage imageNamed:@"iconfont-unie61e"] forState:UIControlStateNormal];
    //添加方法
    [backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *outLayerView =[[UIView alloc]initWithFrame:CGRectMake(space*2, space*2, KSWidth-space*4, KSHeight-space*4-64)];
    //    边框效果：
    //    [layerView.layer setCornerRadius:10];
    [outLayerView.layer setMasksToBounds:YES];//设置边框可见
    outLayerView.layer.borderColor = [[UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1] CGColor];
    [outLayerView.layer setBorderWidth:0.8];
    [self.view addSubview:outLayerView];
    //    阴影层：
    outLayerView.layer.shadowOffset = CGSizeMake(0, 3);
    outLayerView.layer.shadowRadius = 5.0;
    outLayerView.layer.shadowColor = [UIColor blackColor].CGColor;
    outLayerView.layer.shadowOpacity = 0.5;
    
    
    UIView *layerView = [[UIView alloc]initWithFrame:CGRectMake(space*2, space*2, KSWidth-space*4, KSHeight-space*4-64)];
    [self.view addSubview:layerView];
    
//    封面图片
    self.coverImageView = [[UIImageView alloc]initWithFrame:CGRectMake(space*3, space*2, KSWidth-space*10, KSWidth-space*10)];
    self.coverImageView.backgroundColor = [UIColor colorWithRed:245 / 255.0 green:245 / 255.0  blue:245 / 255.0 alpha:1];
    self.coverImageView.alpha = 0.5;
    [layerView addSubview:self.coverImageView];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, KSWidth-space*5, KSWidth-space*4, space*3)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = @"未输入标题";
    self.titleLabel.textColor = [UIColor grayColor];
    self.titleLabel.font = [UIFont systemFontOfSize:18];
//    self.titleLabel.backgroundColor = [UIColor redColor];
    
//    线条
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(space*3, space*3, KSWidth-space*10, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    lineView.alpha = 0.5;
    [self.titleLabel addSubview:lineView];
    [layerView addSubview:self.titleLabel];
  
//   小圆圈
    self.cirleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KSWidth/3-space, KSWidth-space, space*1.5, space*1.5)];
//    self.cirleImageView.image = [UIImage imageNamed:@"iconfont-yuanquanGray"];
    [layerView addSubview:self.cirleImageView];
    
//   标签
    self.tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(KSWidth/3+space*2, KSWidth-space, space*7, space*1.5)];
//    self.tagLabel.text = @"未选择频道";
//    self.tagLabel.backgroundColor = [UIColor redColor];
    
    self.tagLabel.textColor = [UIColor grayColor];
//    self.tagLabel.textAlignment = NSTextAlignmentCenter;
    self.tagLabel.font = [UIFont systemFontOfSize:14];
    [layerView addSubview:self.tagLabel];
    
//    用户头像
    self.headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KSWidth/4, KSWidth+space*5, space*2, space*2)];
    self.headerImageView.layer.cornerRadius = space;
    self.headerImageView.layer.masksToBounds = YES;
//    self.headerImageView = self.userHeader;
    [layerView addSubview:self.headerImageView];
    
    
//    用户名称
    self.userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(KSWidth/3+space*1.5, KSWidth+space*5, space*8, space*2)];
//    self.userNameLabel.textAlignment = NSTextAlignmentCenter;
//    self.userNameLabel.backgroundColor = [UIColor redColor];
    self.userNameLabel.textColor = [UIColor blackColor];
    self.userNameLabel.font = [UIFont systemFontOfSize:15];
    self.userNameLabel.text = self.userName;
    [layerView addSubview:self.userNameLabel];
    
    
//    轻拍事件跳转到发布详情界面
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [layerView addGestureRecognizer:tap];

}

//  轻拍跳转事件方法
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    AddDetailController *addDetailVc = [[AddDetailController alloc]init];
    __weak AddController *blockSelf = self;
    addDetailVc.block = ^(UIImage *image,NSString *text,NSInteger state)
    {
        blockSelf.coverImageView.image = image;
        blockSelf.titleLabel.text = text;
        blockSelf.state = state;
        
    };
    
    [self.navigationController pushViewController:addDetailVc  animated:YES];
}

-(void)backBtnAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


//// 发布
//-(void)releaseBtnAction
//{
//    NSLog(@"发布成功");
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
